from textual.app import App, ComposeResult
from textual.widgets import Header, Footer, Tab, TabPane, TabbedContent, Tabs, Markdown
from textual.binding import Binding

from pathlib import Path
import sys

sys.path.append(Path(__file__).parent.parent.absolute())


# from spark_store_app.data.package import 

class TabsApp(App):
    
    BINDINGS = [
        Binding("q", "quit_app", "Quit"),
    ]

    def action_quit_app(self) -> None:
        self.exit(0)

    def compose(self) -> ComposeResult:
        yield Header()
        # yield TabbedContent(
            # TabPane("Tab 1", id="tab1"),
        # )
        yield Tabs()
        yield Markdown()
        yield Footer()

    categoirs = ['社交沟通','编程开发','游戏娱乐','图形图像','音乐欣赏','网络应用','办公学习','其他应用','阅读翻译','主题美化','系统工具','视频播放']


    def on_mount(self) -> None:
        '''初始化'''
        tabs = self.query_one(Tabs)
        tabs.clear()
        ([(lambda x: tabs.add_tab(x))(x) for x in self.categoirs])

        # tabs.add_tab(Tab("Tab 2"))
        # tabs.add_tab(Tab("Tab 3"))

    def on_tabs_tab_activated(self, event:Tabs.TabActivated):
        # event.tab
        self.notify(event.tab.label_text, timeout=0.3)
        self.query_one(Markdown).update(f"""
# {event.tab.label_text}
                                        """)

if __name__ == "__main__":
    app = TabsApp()
    app.run()